<template>
  <div class="covidNum">
    <div class="content">
      <div class="title">
        数据更新至 {{ formatData(covidNumber.modifyTime) }}
      </div>
      <ul class="wrap">
        <li>
          <div class="number">
            <span>较昨日</span
            >{{ caseNumChange(covidNumber.currentConfirmedIncr) }}
          </div>
          <div class="bold">{{ covidNumber.currentConfirmedCount }}</div>
          <strong>现存确诊</strong>
        </li>
        <li>
          <div class="number">
            <span>较昨日</span>{{ caseNumChange(covidNumber.suspectedIncr) }}
          </div>
          <div class="bold">{{ covidNumber.suspectedCount }}</div>
          <strong>境外输入</strong>
        </li>
        <li>
          <div class="number">
            <span>较昨日</span>{{ caseNumChange(covidNumber.seriousIncr) }}
          </div>
          <div class="bold">{{ covidNumber.seriousCount }}</div>
          <strong>现存无症状</strong>
        </li>
        <li>
          <div class="number">
            <span>较昨日</span>{{ caseNumChange(covidNumber.confirmedIncr) }}
          </div>
          <div class="bold">{{ covidNumber.confirmedCount }}</div>
          <strong>累计确诊</strong>
        </li>
        <li>
          <div class="number">
            <span>较昨日</span> {{ caseNumChange(covidNumber.deadIncr) }}
          </div>
          <div class="bold">{{ covidNumber.deadCount }}</div>
          <strong>累计死亡</strong>
        </li>
        <li>
          <div class="number">
            <span>较昨日</span> {{ caseNumChange(covidNumber.curedIncr) }}
          </div>
          <div class="bold">{{ covidNumber.curedCount }}</div>
          <strong>累计治愈</strong>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import CovidInfo from "./CovidInfo.vue";
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）

export default {
  name: "CovidInfo",
  components: {
    CovidInfo,
  },
  // 定义属性
  data() {
    return {};
  },
  props: {
    // 接收Home父组件传过来的数据
    covidNumber: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {},
  // 监控data中的数据变化
  watch: {},

  methods: {
    //过滤较昨日的数据，显示+/-
    caseNumChange(value) {
      if (value >= 0) {
        return "+" + value;
      } else {
        return value;
      }
    },
    //时间戳过滤器
    formatData(date) {
      var date = new Date(date);
      var YY = date.getFullYear();
      var MM = date.getMonth() + 1;
      var DD = date.getDate();
      var hh = date.getHours();
      var mm = date.getMinutes();
      function fun(num) {
        return (num = num > 9 ? num : "0" + num);
      }
      return YY + "-" + fun(MM) + "-" + fun(DD) + " " + fun(hh) + ":" + fun(mm);
    },
  },
};
</script>

<style lang="less" scoped>
.covidNum {
  border-top: 1px solid #eee;
  color: rgb(7, 6, 6);
  letter-spacing: 0.01rem;
  .content {
    background: #fff;
    padding: 0.3rem;
    min-height: 2rem;
    border-radius: 0.2rem 0.2rem 0 0;
    .title {
      color: #666;
      margin-bottom: 0.3rem;
    }
  }
  .wrap {
    display: flex;
    flex-wrap: wrap;
    padding-top: 0.2rem;
    border-radius: 0.1rem;
    box-shadow: 0 0 3px 2px rgba(194, 192, 192, 0.2);
    li {
      width: 33.33333%;
      text-align: center;
      margin-bottom: 0.24rem;
      position: relative;
      font-size: 0.3rem;
      line-height: 0.5rem;

      .number {
        span {
          color: #777;
          font-weight: bold;
        }
      }
      strong {
        color: #333;
      }
    }
    // 1 2 3-  4 5 6-
    li::after {
      content: "";
      display: block;
      position: absolute;
      right: 1px;
      top: 0.3rem;
      height: 0.8rem;
      border-right: 1px solid #eee;
    }
    li:nth-child(3n)::after {
      content: "";
      border-right: 0;
    }
    .bold {
      font-weight: bold;
      font-size: 0.36rem;
    }
    li:nth-child(1) {
      color: red;
    }
    li:nth-child(2) {
      color: rgb(18, 143, 14);
    }
    li:nth-child(3) {
      color: orange;
    }
    li:nth-child(4) {
      color: rgb(189, 19, 98);
    }
    li:nth-child(5) {
      color: rgb(223, 208, 7);
    }
    li:nth-child(6) {
      color: rgb(8, 110, 194);
    }
  }
  // .wrapper {
  //   display: flex;
  //   margin-top: 0.2rem;
  //   margin-bottom: 0.2rem;
  //   flex-wrap: wrap;
  //   font-size: 14px;
  //   border: 1px solid #eee;
  //   .item {
  //     width: 33.33%;
  //     text-align: center;
  //     margin-bottom: 0.2rem;
  //     margin-top: 0.2rem;
  //     strong {
  //       display: block;
  //     }
  //   }
  // }
}
</style>
